package com.benio.ycfdisplayer.fresco;

import android.graphics.drawable.Animatable;
import android.view.View;

import com.benio.ycfdisplayer.displayer.DisplayListener;
import com.benio.ycfdisplayer.displayer.OnStartListener;
import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.imagepipeline.image.ImageInfo;

class ControllerListenerWrapper extends BaseControllerListener<ImageInfo> {
    private DisplayListener mListener;
    private String mUri;
    private View mView;

    public ControllerListenerWrapper(String uri, View view, DisplayListener listener) {
        mListener = listener;
        mUri = uri;
        mView = view;
    }

    @Override
    public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
        if (mListener != null) {
            mListener.onSuccess(mUri, mView, imageInfo);
        }
    }

    @Override
    public void onSubmit(String id, Object callerContext) {
        if (mListener != null && mListener instanceof OnStartListener) {
            ((OnStartListener) mListener).onStart(mUri, mView);
        }
    }

    @Override
    public void onFailure(String id, Throwable throwable) {
        if (mListener != null) {
            mListener.onFailure(mUri, mView, throwable);
        }
    }
}